
//// Data cleaning 2019 ANES
//// Download 2019 ANES data from ANES website (https://electionstudies.org/data-center/2019-pilot-study/)
//// Import file - make sure to import "familyinc_new" as numeric

/// Left as-is: Census region "region", survey weight "weight"
destring weight, replace

/// White "white"
tab race
gen white = 0
replace white = 1 if race == 1

/// Black "black"
gen black = 0
replace black = 1 if race == 2

/// Hispanic "hisp"
gen hisp = 0
replace hisp = 1 if race == 3

/// Age "age"
gen age = (birthyr-1926)/74
tab age

/// Female "female"
gen female = 0
replace female = 1 if gender == 2

/// College "college"
gen college = 0
replace college = 1 if educ > 4

/// Family income "inc"
gen inc = .
replace inc = 14 if faminc_new == 15
replace inc = 14 if faminc_new == 16
replace inc = . if faminc_new == 97
replace inc = faminc_new if faminc_new < 15
replace inc = (inc-1)/13

/// Religious importance "relig"
gen relig = ((-pew_religimp)+4)/3

/// Born Again Christian "bornagain"
gen bornagain = 0
replace bornagain = 1 if pew_bornagain==1

/// ideology "ideo"
gen ideo = .
replace ideo = 0 if ideo5==1
replace ideo = .25 if ideo5==2
replace ideo = .5 if ideo5==3
replace ideo=.75 if ideo5 == 4
replace ideo = 1 if ideo5==5
tab ideo ideo5

/// partisanship "pid"
gen pid = (pid7-1)/6
replace pid = . if pid > 1

/// Rural resident "rurallive" and "ruralres"
tab liveurban
gen rurallive = 0
replace rurallive = 1 if liveurban < 3
gen ruralres = rurallive

/// Grew up rural "ruralgrow"
tab youthurban 
gen ruralgrow = 0
replace ruralgrow = 1 if youthurban < 3

/// Rural category "ruralcat"
gen ruralcat = .
replace ruralcat = 0 if rurallive==1 & ruralgrow==1
replace ruralcat = 1 if rurallive==1 & ruralgrow==0
replace ruralcat = 2 if rurallive==0 & ruralgrow==1
replace ruralcat = 3 if rurallive==0 & ruralgrow==0


/// racial resentment "rr"
tab rr1
gen rr__1 = rr1-1
tab rr__1
replace rr__1 = . if rr__1 == -8
gen rr_1 = rr__1/4

tab rr2
gen rr__2 = (-rr2 + 5)
tab rr__2
replace rr__2 = . if rr__2 == 12
gen rr_2 = rr__2/4

tab rr3
gen rr__3 = (-rr3 + 5)
tab rr__3
replace rr__3 = . if rr__3 == 12
gen rr_3 = rr__3/4

tab rr4
gen rr__4 = rr4-1
tab rr__4
replace rr__4 = . if rr__4 == -8
gen rr_4 = rr__4/4

corr rr_1 rr_2 rr_3 rr_4

egen rr = rmean(rr_1 rr_2 rr_3 rr_4)


/// Rural identity (binary) "rasocid_binary"
tab placeid1b
gen rurid = 0
replace rurid = 1 if placeid1b > 2.5
tab rurid placeid1b

tab placeid1a
gen rurid2 = 0
replace rurid2 = 1 if placeid1a == 3
replace rurid2 = 1 if placeid1a == 4

gen rasocid_binary = .
replace rasocid_binary = 1 if rurid2 == 1
replace rasocid_binary = 1 if rurid == 1
replace rasocid_binary = 0 if rasocid_binary !=1
tab rasocid_binary


/// Multiculturalism "multicult"
gen mc1 = ((-diversity5)+5)/4
replace mc1 = . if mc1 == 1.5

gen mc2 = ((-diversity7)+7)/6
replace mc2 = . if mc2 > 1

gen mc3 = ((-language)+5)/4

egen multicult = rmean(mc1 mc2 mc3)




